<?php include load_template('_subnav.php')?>
<style type="text/css" media="screen">
/* <![CDATA[ */

    #breadcrumb {
        padding:3px;      
        margin:5px 0;  
        font-size:medium;
        border-bottom:1px solid #ccc;
    }
    #add_new table td{
        text-align:left;
    }
    #help_legend {
        margin: 3px;
        font-size: x-small;
        text-align: right;
    }
/* ]]> */
</style>
<h1>File Browser</h1>


<?php include load_template('_add.php') ?>

<div id='breadcrumb'>Browsing: <?php echo  create_breadcrumb($folder_path) ?></div>
<div id="help_legend">
    <b>Legend</b>:
    Delete File <img src="<?php echo get_installed_path()?>/images/admin/delete.gif">
    Modify Image <img src="<?php echo get_installed_path()?>/images/admin/modify.gif">
    &nbsp;&nbsp;&nbsp;
    <?php 
        echo 'View type: '.form_tag($redirect, array('style'=>'display:inline')).
             hidden_field_tag('file_folder_id', $file_folder_id).
             select_tag('files_filter_by', options_for_select($file_filters, $file_filter_selected),
                        array('onchange'=>'this.form.submit()','include_blank'=>false)).
             end_form_tag();
    ?>
</div>
<table width='100%' cellpadding='2' cellspacing='1' style='border:1px solid #ccc'>
    <tr>
        <th>Name</th>
        <th width='1%'>Created</th>
        <th width='1%'></th>
    </tr>
<?php
    $odd_or_even = 0;
    if ( count($all_folders) > 0 )
    {                
        $goto = url_for($redirect);
        foreach( $all_folders as $folder )
        {
            $odd_or_even = 1 - $odd_or_even;
            if (has_access_to('Files::Delete Folders')) {
                $delete  = form_tag('delete').
                           hidden_field_tag('action','delete_folder').
                           hidden_field_tag('redirect',$redirect).
                           hidden_field_tag('file_folder_id',$file_folder_id).
                           hidden_field_tag('id',$folder['id']).
                           image_submit_tag('delete',get_installed_path().'/images/admin/delete.gif',array('onclick'=>"return confirm('Are you sure you want to delete this folder? It will also delete all files and folders it contains.')")).
                           end_form_tag();
            } else {
                $delete = '';
            }
            echo "<tr class='alt{$odd_or_even}'>
                <td><img src='".get_installed_path()."/images/admin/icons/foldericon.png' align='absmiddle' /> ".
                link_to($folder['name'],"$goto?file_folder_id={$folder['id']}")."</td>
                <td nowrap='nowrap'>".date_format($folder['created'],"%D")."</td>
                <td nowrap='nowrap'>$delete</td>
                </tr>";
        }
    }
    if ( count($all_files) > 0 )
    {                
        foreach( $all_files as $file )
        {
            $odd_or_even = 1 - $odd_or_even;
            if (has_access_to('Files::Delete Files')) {
                $delete  = form_tag('delete', array('style'=>'display:inline') ).
                           hidden_field_tag('action','delete_file').
                           hidden_field_tag('redirect',$redirect).
                           hidden_field_tag('file_folder_id',$file_folder_id).
                           hidden_field_tag('id',$file['id']).
                           image_submit_tag('delete',
                           get_installed_path().'/images/admin/delete.gif',
                            array('onclick'=>"return confirm('Are you sure you want to delete this file?')")).
                           end_form_tag();
            } else {
                $delete = '';
            }
            $img_modify = '';
            if ( preg_match("!^image/!i", $file['type']) )
            {
                $img_modify = form_tag('crop_image', array('style'=>'display:inline') ).
                           hidden_field_tag('redirect',$redirect).
                           hidden_field_tag('file_folder_id',$file_folder_id).
                           hidden_field_tag('id',$file['id']).                              
                           image_submit_tag('modify',get_installed_path().'/images/admin/modify.gif',
                                            array('alt'=>'Modify Image')).
                           end_form_tag();
            }
            echo "<tr class='alt{$odd_or_even}'>
                  <td>".get_icon($file['type']).' '.
                    link_to($file['name'],
                    path_to_file($file['file_folder_id'])."/".rawurlencode($file['name']),
                    array('target'=>'_blank')) .
                  "</td>
                  <td nowrap='nowrap'>".date_format($file['created'],"%D")."</td>
                  <td nowrap='nowrap'>$img_modify $delete</td>
                  </tr>";
        }
    }
    if (count($all_files) == 0 && count($all_folders) == 0) echo '<tr><td colspan="3" align="center" class="alt0"><em>No files</em></td></tr>';
?>
</table>